import enum


@enum.unique
class OnlineStage(enum.Enum):
    NOT_EXIST = None
    CONNECTED = 1
    REGISTERED = 2
    CLOSED = 3


@enum.unique
class ActType(enum.Enum):
    REGISTER = 1
    LOCAL_REGISTER = 2
    BATCH_REGISTER = 3
    USER_ONLINE = 8
    USER_OFFLINE = 9
    DEVICE_ONLINE = 10
    DEVICE_OFFLINE = 11
    # 状态
    STATE_MESSAGE = 7
    UNIT_STATE = 12
    # 笔记
    SUBSCRIBE_HANDWRITING = 13
    UNSUBSCRIBE_HANDWRITING = 14
    # 聊天相关
    TEXT_CHAT = 15  # 文本聊天
    EMOJI_CHAT = 16  # 表情聊天
    IMAGE_CHAT = 18  # 图片聊天
    CHAT_BLACKLIST = 26  # 黑名单
    # 杂项
    MESSAGE_ACK = 19  #
    # 计数
    COUNTER = 40


@enum.unique
class UserRole(enum.Enum):
    GUEST = 0
    TEACHER = 1
    STUDENT = 2


@enum.unique
class SessionRole(enum.Enum):
    GUEST = 0
    TEACHER = 1
    STUDENT = 2

    @classmethod
    def from_user_role(cls, user_role):
        return cls(user_role.value)


@enum.unique
class UserGroup(enum.Enum):
    ALL = 'A'
    TEACHER = 'T'
    STUDENT = 'S'
    GUEST = 'G'
    DEVICE = 'D'

    @classmethod
    def from_session_role(cls, session_role):
        if session_role.value == SessionRole.TEACHER.value:
            return cls.TEACHER
        elif session_role.value == SessionRole.STUDENT.value:
            return cls.STUDENT
        elif session_role.value == SessionRole.GUEST.value:
            return cls.GUEST
        else:
            return cls.DEVICE

    @classmethod
    def from_user_role(cls, user_role):
        session_role = SessionRole.from_user_role(user_role)
        return cls.from_session_role(session_role)
